package com.notecalendar.quartz.exception;

import java.util.HashMap;
import java.util.Map;

/**
 * Exception for methods on QuartzCalendar class
 * @author angelcereijo
 *
 */
public class QuartzCalendarException extends Exception{
	//Exceptions codes
	public final static int MINUTE_VALUE_EXCEPTION = 0;
	public final static int HOUR_VALUE_EXCEPTION = 1;
	public final static int DAY_VALUE_EXCEPTION = 2;
	public final static int DAY_MONTH_VALUE_EXCEPTION = 3;
	public final static int MONTH_VALUE_EXCEPTION = 4;
	public final static int YEAR_VALUE_EXCEPTION = 5;
	
	
	//Exceptions description
	public final static String MINUTE_VALUE_EXCEPTION_DESC = "Minute values must be among 0 and 59,both inclusive";
	public final static String HOUR_VALUE_EXCEPTION_DESC = "Hour values must be among 0 and 23,both inclusive";
	public final static String DAY_VALUE_EXCEPTION_DESC = "Day values must be among 1 and 31,both inclusive";
	public final static String DAY_MONTH_VALUE_EXCEPTION_DESC = "Day value is not valid for specific month";
	public final static String MONTH_VALUE_EXCEPTION_DESC = "Month values must be among 1 and 12,both inclusive";
	public final static String YEAR_VALUE_EXCEPTION_DESC = "Year value must be major or equal to actual year";
	
	
	//Map for join codes and descriptions
	private final static Map<Integer, String> MAP_CODE_DESCRIPTION = 
		new HashMap<Integer, String>();
	{
		MAP_CODE_DESCRIPTION.put(MINUTE_VALUE_EXCEPTION, MINUTE_VALUE_EXCEPTION_DESC);
		MAP_CODE_DESCRIPTION.put(HOUR_VALUE_EXCEPTION, HOUR_VALUE_EXCEPTION_DESC);
		MAP_CODE_DESCRIPTION.put(DAY_VALUE_EXCEPTION, DAY_VALUE_EXCEPTION_DESC);
		MAP_CODE_DESCRIPTION.put(DAY_MONTH_VALUE_EXCEPTION, DAY_MONTH_VALUE_EXCEPTION_DESC);
		MAP_CODE_DESCRIPTION.put(MONTH_VALUE_EXCEPTION, MONTH_VALUE_EXCEPTION_DESC);
		MAP_CODE_DESCRIPTION.put(YEAR_VALUE_EXCEPTION, YEAR_VALUE_EXCEPTION_DESC);
	}
	
	
	private int exceptionType;
	private String exceptionTypeDesc;
	
	/**
	 * 
	 * @param exceptionType one of the valid exception codes.
	 */
	public QuartzCalendarException(int exceptionType){
		setExceptionType(exceptionType);
		setExceptionTypeDesc(MAP_CODE_DESCRIPTION.get(exceptionTypeDesc));
	}
	
	
	private void setExceptionType(int exceptionType) {
		this.exceptionType = exceptionType;
		
	}
	
	private void setExceptionTypeDesc(String exceptionTypeDesc) {
		this.exceptionTypeDesc = exceptionTypeDesc;
	}
	
	public int getExceptionType() {
		return exceptionType;
	}
	
	public String getExceptionTypeDesc() {
		return exceptionTypeDesc;
	}
	
}
